package com.yc.thread;

/**
 * yield:让位，屈服
 */
public class Test13_yield {
    public static void main(String[] args) {
        YieLdOne y1 =new YieLdOne();
        YieLdOne y2 =new YieLdOne();
        Thread t1 = new Thread(y1, "a");
        Thread t2 = new Thread(y2, "b");

        t1.setPriority(1);
        t1.start();

        t2.setPriority(10);
        t2.start();

    }
}

class YieLdOne implements Runnable{
    @Override
    public void run() {
        if ("a".equals(Thread.currentThread().getName())) {
            Thread.yield();
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        for (int i=0;i<10;i++) {
            System.out.println(Thread.currentThread().getName()+":"+i);
        }
    }
}
